import 'package:flutter/material.dart';

import '../../dialogs/account_disabled_dialog.dart';
import '../../dialogs/unauthenticated_dialog.dart';
import '../../dialogs/update_dialog.dart';
import '../../presentation/offers_page/cubit/offers_screen.dart';
import 'navigator_service.dart';


showMessage(String message) {
  ScaffoldMessenger.of(NavigatorService.navigatorKey.currentContext!).removeCurrentSnackBar();
  ScaffoldMessenger.of(NavigatorService.navigatorKey.currentContext!).showSnackBar(
    SnackBar(
      backgroundColor:Colors.orange,
      content: Text(
        message,
        textAlign: TextAlign.center,
        style: const TextStyle(
          color: Colors.black,
        ),
      ),
      duration: const Duration(seconds: 3),
      behavior: SnackBarBehavior.floating,
    ),
  );
}

showSuccessMessage({required String message, Color color = Colors.green}) {
  ScaffoldMessenger.of(NavigatorService.navigatorKey.currentContext!).showSnackBar(
    SnackBar(
      backgroundColor:color,
      content: Text(
        message,
        textAlign: TextAlign.center,
      ),
      duration: const Duration(seconds: 2),
      behavior: SnackBarBehavior.floating,
    ),
  );
}

showErrorMessage({required String message, Color color = Colors.red}) {
  ScaffoldMessenger.of(NavigatorService.navigatorKey.currentContext!).showSnackBar(
    SnackBar(
      backgroundColor:color,
      content: Text(
        message,
        textAlign: TextAlign.center,
      ),
      duration: const Duration(seconds: 3),
      behavior: SnackBarBehavior.floating,
    ),
  );
}

showMessageAndButton({required String message, Color color = Colors.red , required Widget child}) {
  ScaffoldMessenger.of(NavigatorService.navigatorKey.currentContext!).showSnackBar(
    SnackBar(
      backgroundColor:color,
      content: Row(
        children: [
          Expanded(
            child: Text(
              message,
              textAlign: TextAlign.center,
            ),
          ),
          child,
        ],
      ),
      duration: const Duration(seconds: 3),
      behavior: SnackBarBehavior.floating,
    ),
  );
}


showUnauthenticatedDialog(){
  showDialog(context: NavigatorService.navigatorKey.currentContext!, builder: (context){
    return const UnauthenticatedDialogBody();
  });
}
showUpdateDialog(String link){
  showDialog(context: NavigatorService.navigatorKey.currentContext!, builder: (context){
    return UpdateDialogBody(
      appLink: link,
    );
  });
}


showOffersScreen(){
  Navigator.of(NavigatorService.navigatorKey.currentContext!).pushAndRemoveUntil(MaterialPageRoute(builder: (context) =>
  const OffersScreen(isRequired: true,)), (Route<dynamic> route) => false);
}

showAccountDisabledDialog(){
  showDialog(context: NavigatorService.navigatorKey.currentContext!, builder: (context){
    return const AccountDisabledDialogBody();
  });
}